package controller;

import dao.PayrecordMapper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pojo.*;
import response.Result;
import service.PayrecordService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;

/**
 * @ClassName 刘星宇
 * @Description TODO
 * @date 2022/12/7 16:48
 * @Version 1.0
 */
@RestController
public class PayrecordController {
    @Resource
    private PayrecordService payrecordService;
    @Resource
    private PayrecordMapper payrecordMapper;
    @RequestMapping("queryPayCondition")
    public Result queryPayCondition(@RequestBody Payrecord payrecord, HttpServletRequest req){
        Page<Payrecord> page=new Page<Payrecord>();
        SCMUser u=(SCMUser) req.getSession().getAttribute("loginUser") ;
        payrecord.setAccount(u.getName());
        page.setCurrentPage(payrecord.getCurrentPage());
        page.setPageSize(payrecord.getPageSize());
        int totalRec=payrecordService.getPayrecordCount(page,payrecord);
        List<Payrecord> payrecords=payrecordService.getPayrecordByPage(page,payrecord);
        page.setTotalRecord(totalRec);
        page.setLists(payrecords);
        return Result.ok(page);
    }
    @RequestMapping("getPayrecordBy")
    public Result getPayrecordBy(@RequestBody Payrecord payrecord, HttpServletRequest req){
        PoItem poitem = new PoItem();
        Soitem soitem =new Soitem();
        poitem.setOrdercode(payrecord.getOrdercode());
        soitem.setOrdercode(payrecord.getOrdercode());
        List<Soitem> so = payrecordMapper.SomainOrdercode(soitem);
        if (so.isEmpty()){
            return Result.ok(payrecordMapper.PomainOrdercode(poitem));
        }else {
            return Result.ok();
        }
    }
}
